package btd.game.dlgs;

import btd.game.activities.R;
import btd.game.activities.SdeskAct;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class SguizeDlg extends Dialog implements OnCheckedChangeListener {
	private SdeskAct owner = null;
	private String komi = "";
	private String time = "";
	private String count = "";
	private RadioButton rKomi4_75 = null;
	private RadioButton rKomi5_75 = null;
	private RadioButton rTimeDefaule = null;
	private RadioButton rTime10 = null;
	private RadioButton rTime5 = null;
	private RadioButton rCount1 = null;
	private RadioButton rCount2 = null;
	private Button bOK = null;
	private Button bBack = null;
	public SguizeDlg(Context context) {
		super(context);
		owner = (SdeskAct) context;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.selectguize);
		bOK = (Button) findViewById(R.id.ButtonOK);
		bOK.setOnClickListener(bOKListener);
		bBack = (Button) findViewById(R.id.ButtonBack);
		bBack.setOnClickListener(bBackListener);
		rKomi4_75 = (RadioButton) findViewById(R.id.RadioButton6_5);
		rKomi4_75.setOnCheckedChangeListener(this);
		rKomi5_75 = (RadioButton) findViewById(R.id.RadioButton7_5);
		rKomi5_75.setOnCheckedChangeListener(this);
		rTimeDefaule = (RadioButton) findViewById(R.id.RadioButtonTDefault);
		rTimeDefaule.setOnCheckedChangeListener(this);
		rTime10 = (RadioButton) findViewById(R.id.RadioButtonT10);
		rTime10.setOnCheckedChangeListener(this);
		rTime5 = (RadioButton) findViewById(R.id.RadioButtonT5);
		rTime5.setOnCheckedChangeListener(this);
		rCount1 = (RadioButton) findViewById(R.id.RadioButtonC1);
		rCount1.setOnCheckedChangeListener(this);
		rCount2 = (RadioButton) findViewById(R.id.RadioButtonC2);
		rCount2.setOnCheckedChangeListener(this);
		
		komi = owner.getResources().getString(R.string.k_4_75);
		time = owner.getResources().getString(R.string.tDefault);
		count = "1";
	}
	
	private View.OnClickListener bOKListener = new View.OnClickListener() {
		public void onClick(View v) {
			owner.setGuize(komi, time, count);
			SguizeDlg.this.cancel();
		}
	};
	
	private View.OnClickListener bBackListener = new View.OnClickListener() {
		public void onClick(View v) {
			SguizeDlg.this.cancel();
		}
	};

	@Override
	public void onCheckedChanged(CompoundButton cb, boolean arg1) {
		RadioButton rb = (RadioButton) cb;
		Resources res = owner.getResources();
		if(rb.getId() == rKomi4_75.getId()) {
			if(rKomi4_75.isChecked()) {
				komi = res.getString(R.string.k_4_75);
			}
		}
		if(rb.getId() == rKomi5_75.getId()) {
			if(rKomi5_75.isChecked()) {
				komi = res.getString(R.string.k_5_75);
			}
		}
		if(rb.getId() == rTimeDefaule.getId()) {
			if(rTimeDefaule.isChecked()) {
				time = res.getString(R.string.tDefault);
			}
		}
		if(rb.getId() == rTime10.getId()) {
			if(rTime10.isChecked()) {
				time = res.getString(R.string.t10);
			}
		}
		if(rb.getId() == rTime5.getId()) {
			if(rTime5.isChecked()) {
				time = res.getString(R.string.t5);
			}
		}
		if(rb.getId() == rCount1.getId()) {
			if(rCount1.isChecked()) {
				count = "1";
			}
		}
		if(rb.getId() == rCount2.getId()) {
			if(rCount2.isChecked()) {
				count = "2";
			}
		}
	}
}
